{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8be89595-8885-4d5e-b1da-1df04eda5c7a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import {\n",
    "  Document,\n",
    "  VectorStoreIndex\n",
    "} from \"npm:llamaindex\";"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "65de03f9-455a-4c59-9089-093cb6998af7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In college, the author studied subjects such as linear algebra and physics, but did not find them particularly interesting. They also slacked off and skipped lectures, leading to gaps in their knowledge. They had a negative experience with their English classes and became resentful and suspicious of higher education. They eventually dropped out of college and did not return until five years later to pick up their papers.\n"
     ]
    }
   ],
   "source": [
    "// Create Document object with essay\n",
    "const resp = await fetch('https://raw.githubusercontent.com/run-llama/LlamaIndexTS/main/packages/core/examples/abramov.txt');\n",
    "const text = await resp.text();\n",
    "const document = new Document({ text });\n",
    "\n",
    "// Split text and create embeddings. Store them in a VectorStoreIndex\n",
    "const index = await VectorStoreIndex.fromDocuments([document]);\n",
    "\n",
    "// Query the index\n",
    "const queryEngine = index.asQueryEngine();\n",
    "const response = await queryEngine.query({\n",
    "    query: \"What did the author do in college?\",\n",
    "});\n",
    "\n",
    "// Output response\n",
    "console.log(response.toString());"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc0ec12f-2062-47af-916d-7c77ca39433a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "68bdd292-5cf7-46e0-8646-51be1f070ad6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Deno",
   "language": "typescript",
   "name": "deno"
  },
  "language_info": {
   "file_extension": ".ts",
   "mimetype": "text/x.typescript",
   "name": "typescript",
   "nb_converter": "script",
   "pygments_lexer": "typescript",
   "version": "5.3.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
